/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipti.br.tag.entity;

import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.ipti.br.tag.util.CalendarUtil;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author root
 */

@Entity
public class ActorCalendar extends AbstractEntity{

    @Temporal(TemporalType.DATE)
    @Column(name="calendar_day")
    private Calendar calendarDay;

    @Temporal(TemporalType.TIME)
    @Column(name="initial_time")
    private Calendar initialTime;

    @Temporal(TemporalType.TIME)
    @Column(name="final_time")
    private Calendar finalTime;

    @Column(length=50, nullable=true)
    private String situation;

    @Lob
    @Column(nullable=true)
    private String obs;

    @ManyToOne
    @JoinColumn(name = "actor_id")
    private Actor actor;

    @ManyToOne
    @JoinColumn(name = "actorSchedule_id", nullable = false)
    private ActorSchedule actorSchedule;

    @ManyToOne
    @JoinColumn(name = "task_id", nullable = false)
    private Task task;

    @ManyToOne
    @JoinColumn(name = "discipline_id", nullable = false)
    private Discipline discipline;

    public ActorCalendar() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = ""
                    + ((this.getCalendarDay() != null) ? CalendarUtil.getFormatedDate(this.getCalendarDay()) : null)
                    + ((this.getActor() != null) ? this.getActor().getId() : null)
                    + ((this.getActorSchedule() != null) ? this.getActorSchedule().getId() : null)
                    + ((this.getTask() != null) ? this.getTask().getId() : null)
                    + ((this.getDiscipline() != null) ? this.getDiscipline().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public ActorCalendar(Calendar calendarDay, Calendar initialTime, Calendar finalTime, Actor actor, ActorSchedule actorSchedule, Task task, Discipline discipline) {
        this.calendarDay = calendarDay;
        this.initialTime = initialTime;
        this.finalTime = finalTime;
        this.actor = actor;
        this.actorSchedule = actorSchedule;
        this.task = task;
        this.discipline = discipline;
//        frequencyList = new ArrayList<Frequency>();
    }

    public ActorCalendar(Calendar calendarDay, Calendar initialTime, Calendar finalTime, String situation, String obs, Actor actor, ActorSchedule actorSchedule, Task task, Discipline discipline) {
        this.calendarDay = calendarDay;
        this.initialTime = initialTime;
        this.finalTime = finalTime;
        this.situation = situation;
        this.obs = obs;
        this.actor = actor;
        this.actorSchedule = actorSchedule;
        this.task = task;
        this.discipline = discipline;
//        frequencyList = new ArrayList<Frequency>();
    }

    public Actor getActor() {
        return actor;
    }

    public void setActor(Actor actor) {
        this.actor = actor;
    }

    public ActorSchedule getActorSchedule() {
        return actorSchedule;
    }

    public void setActorSchedule(ActorSchedule actorSchedule) {
        this.actorSchedule = actorSchedule;
    }

    public Calendar getCalendarDay() {
        return calendarDay;
    }

    public void setCalendarDay(Calendar calendarDay) {
        this.calendarDay = calendarDay;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public Discipline getDiscipline() {
        return discipline;
    }

    public void setDiscipline(Discipline discipline) {
        this.discipline = discipline;
    }

    public Calendar getFinalTime() {
        return finalTime;
    }

    public void setFinalTime(Calendar finalTime) {
        this.finalTime = finalTime;
    }

    public Calendar getInitialTime() {
        return initialTime;
    }

    public void setInitialTime(Calendar initialTime) {
        this.initialTime = initialTime;
    }

    public String getObs() {
        return obs;
    }

    public void setObs(String obs) {
        this.obs = obs;
    }

    public String getSituation() {
        return situation;
    }

    public void setSituation(String situation) {
        this.situation = situation;
    }
}
